home *** CD-ROM | disk | FTP | other *** search
/ MacAdvocate 2 / MACADVCT.ISO / mac / Goodies / Fun Stuff / Utilities / UltraFind / AppleScript™ Examples / UTF Find Text < prev    next >
Text File  |  1996-05-30  |  4KB  |  90 lines

  1. copy the version of application "UltraFind 2.2" to currentVersion
  2. if currentVersion is less than "2.1.3" then
  3.     display dialog "To run this script you must have UltraFind version 2.1.3 or greater" & return & return & ┬
  4.         "The version of UltraFind you are running is only " & currentVersion buttons "Cancel"
  5. else
  6.     set numFiles to 0
  7.     tell application "UltraFind 2.2"
  8.         clear
  9.         
  10.         set the text of fileName of its searchRoutine to "read me"
  11.         set the searchType of fileName of its searchRoutine to nameIs
  12.         
  13.         set the text of targetWord 1 of searchText of its searchRoutine to "apple"
  14.         set the text of targetWord 2 of searchText of its searchRoutine to "version"
  15.         set the text of targetWord 3 of searchText of its searchRoutine to "project"
  16.         
  17.         --the following scripts are commented out and are included only as examples:
  18.         
  19.         -- example of how to use UltraFind's Thesaurus:
  20.         --    set the XRef of targetWord 1 of searchText of its searchRoutine to XRefON
  21.         
  22.         -- use this to find only those files which contain both target words:
  23.         --    set options of searchText of its searchRoutine to matchAll
  24.         
  25.         -- use this only if you want to search ALL types of files (including graphics images, application, etc.
  26.         -- without this only documents likely to contain text will be searched:
  27.         --    set options of searchText of its searchRoutine to searchAll
  28.         
  29.         -- use this only if you want to search the files' resource forks:
  30.         --    set options of searchText of its searchRoutine to searchResources
  31.         
  32.         -- you may want to search only those files in a specific directory, e.g.:
  33.         --    set the confineDirectory of its searchRoutine to "Hard Disk:Text Files"
  34.         
  35.         --set the maximum number of found words to show, e.g. 3
  36.         set showWords of searchText of its searchRoutine to 1
  37.         
  38.         scan
  39.         changeView finderView --make sure the list window is in FINDER VIEW to process the text found
  40.         copy the result to numFiles
  41.     end tell
  42.     
  43.     if numFiles is greater than 0 then
  44.         
  45.         --process the list in TEXT VIEW to get individual words and offsets
  46.         tell application "UltraFind 2.2" to changeView textView
  47.         copy the result to numRecords
  48.         set recNum to 1
  49.         set fileNum to 1
  50.         set dialogtext to ""
  51.         repeat until recNum is greater than numRecords
  52.             
  53.             tell application "UltraFind 2.2"
  54.                 copy (the fileName of fileRecord recNum) to fName
  55.                 copy (the textFound of fileRecord recNum) to fText
  56.                 copy (the textOffset of fileRecord recNum) to fOffset
  57.             end tell
  58.             set recNum to recNum + 1
  59.             
  60.             --in TEXT view each file found has one MASTER record and one or more TEXT records
  61.             --the MASTER record returns a list of all the words found but has no textoffset
  62.             --the TEXT record returns the words found and its location (textoffset) in characters from the start of the file
  63.             if fOffset is equal to "" then --its a master record
  64.                 --check if previous file's results dialog needs to be displayed
  65.                 if dialogtext is not equal to "" then
  66.                     set dialogtext to dialogtext & return
  67.                     display dialog dialogtext buttons {"Cancel", "Next"} default button 2
  68.                 end if
  69.                 set dialogtext to "Found file " & (fileNum as text) & " of " & (numFiles as text) & return & return & ┬
  70.                     "Text Search Results for File '" & fName & "' :" & return & return
  71.                 set fileNum to fileNum + 1
  72.             else
  73.                 set dialogtext to dialogtext & "At offset " & fOffset & " found '" & fText & "'" & return
  74.             end if
  75.         end repeat
  76.         
  77.         --repeat with fileNum from 1 to numFiles
  78.         --    tell application "UltraFind 2.1"
  79.         --        copy (the fileName of fileRecord fileNum) to fName
  80.         --        copy (the textFound of fileRecord fileNum) to fText
  81.         --    end tell
  82.         
  83.         --    display dialog "Found file " & (fileNum as text) & " of " & (numFiles as text) & return & return & ┬
  84.         --        "Filename : " & fName & return & ┬
  85.         --        "Found words: '" & fText & "'" & return & return ┬
  86.         --        buttons {"Cancel", "Next"} default button 2
  87.         --end repeat
  88.         
  89.     end if
  90. end if